package com.TetrisII.entities;

import java.util.ArrayList;

import com.TetrisII.control.ShapeControllers;
import com.TetrisII.extra.model.BShape;
import com.TetrisII.extra.model.EShape;
import com.TetrisII.extra.model.IIShape;
import com.TetrisII.extra.model.PShape;
import com.TetrisII.model.IShape;
import com.TetrisII.model.JShape;
import com.TetrisII.model.LShape;
import com.TetrisII.model.OShape;
import com.TetrisII.model.S_Shape;
import com.TetrisII.model.TShape;
import com.TetrisII.model.ZShape;

/**
 * 工厂类，用来储存和生产图形
 * 
 * @author Administrator
 *
 */
public class ShapeFactory {
	ArrayList<Shape> shapes;
	private Shape shape;
	private int type;
	private int randomType;// 随机产生几种
	private int status;// 第几种变换

	/**
	 * 构造方法把图形加入到图形工厂中
	 */
	public ShapeFactory() {

		shapes = new ArrayList<>();
		shapes.add(new LShape());
		shapes.add(new IShape());
		shapes.add(new JShape());
		shapes.add(new ZShape());
		shapes.add(new TShape());
		shapes.add(new OShape());
		shapes.add(new S_Shape());
		// 额外4个方块
		shapes.add(new BShape());
		shapes.add(new EShape());
		shapes.add(new IIShape());
		shapes.add(new PShape());

		randomType = 7;
	}

	/**
	 * 工厂返回任意图形
	 * 
	 * @return
	 */
	public Shape getShape() {

		type = (int) (Math.random() * randomType);
		shape = shapes.get(type);// 产生方块的类型
		shape.initShape();// 初始化方块
		status = (int) (Math.random() * 4);
		shape.setStatus(status);// 类型中的第几种

		return shape;

	}

	/**
	 * 等级
	 * 
	 * @param level
	 *            输入级别，1产生7中，2产生9种，3产生11种
	 */
	public void levelShape(int level) {
		switch (level) {
		case 1:
			randomType = 7;
			System.out.println("7种");
			break;
		case 2:
			randomType = 9;
			System.out.println("9种");
			break;
		case 3:
			randomType = 11;
			System.out.println("11种");
			break;

		default:
			break;
		}
	}
}
